import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: '首页',
      icon: 'dashboard'
    }
  }]
},

{
  path: '/information',
  component: Layout,
  redirect: '/information/table',
  children: [{
    path: 'information',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/information/index'),
    meta: {
      title: '个人信息',
      icon: 'user'
    }
  }
  ]
},
{
  path: '/editinformation',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index/:sno',
    name: 'editinformation',
    component: () => import('@/views/form/editinformation/index'),
    meta: {
      title: '修改个人信息',
      icon: 'form'
    }
  }]
},

{
  path: '/course',
  component: Layout,
  // alwaysShow: true,
  redirect: '/course/table',
  name: 'Example',
  meta: {
    title: '课程管理',
    icon: 'example'
  },
  children: [{
    path: 'tree1',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/course/tree1/index'),
    meta: {
      title: '课程信息',
      icon: 'table'
    }
  },
  {
    path: 'tree2',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/course/tree2/index'),
    meta: {
      title: '课程记录',
      icon: 'table'
    }
  }
  ]
},
{
  path: '/editcourse',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index/:code',
    name: 'editcourse',
    component: () => import('@/views/form/course/editcourse/index'),
    meta: {
      title: '修改课程',
      icon: 'form'
    }
  }]
},
{
  path: '/attendance',
  component: Layout,
  redirect: '/attendance/table',
  children: [{
    path: 'attendance',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/attendance/index'),
    meta: {
      title: '考勤管理',
      icon: 'example'
    }
  }
  ]
},

{
  path: '/score',
  component: Layout,
  redirect: '/score/table',
  children: [{
    path: 'score',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/score/index'),
    meta: {
      title: '成绩管理',
      icon: 'example'
    }
  }
  ]
},
{
  path: '/editscore',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index/:cid',
    name: 'editscore',
    component: () => import('@/views/form/editscore/index'),
    meta: {
      title: '修改成绩',
      icon: 'form'
    }
  }]
},
{
  path: '/teacher',
  component: Layout,
  redirect: '/teacher/table',
  children: [{
    path: 'teacher',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/teacher/index'),
    meta: {
      title: '教师管理',
      icon: 'example'
    }
  }
  ]
},

{
  path: '/form/teacher',
  hidden: true,
  component: Layout,
  // redirect: '/teacher/table',
  children: [{
    path: 'index/:code',
    name: 'teacher_edit',
    component: () => import('@/views/form/teacher/index'),
    meta: {
      title: '教师编辑',
      icon: 'form'
    }
  }
  ]
},

{
  path: '/student',
  component: Layout,
  redirect: '/student/table',
  children: [{
    path: 'student',
    name: 'Table',
    component: () => import('@/views/users/admin_modules/student/index'),
    meta: {
      title: '学生管理',
      icon: 'example'
    }
  }
  ]
},
{
  path: '/form/student',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index/:code',
    // path: 'index',
    name: 'Form',
    component: () => import('@/views/form/student/index'),
    meta: {
      title: 'studentForm',
      icon: 'form'
    }
  }]
},
{
  path: '/form/student',
  component: Layout,
  hidden: true,
  children: [{
    path: 'add',
    name: 'Form',
    component: () => import('@/views/form/student/add'),
    meta: {
      title: 'studentForm',
      icon: 'form'
    }
  }]
},

{
  path: '/all',
  component: Layout,
  redirect: '/all/table',
  name: '查询所有账号',
      // meta: {
      //   title: '查询账号',
      //   icon: 'table'
      // },
  children: [{
    path: 'all',
    name: 'all',
    component: () => import('@/views/users/admin_modules/all/index'),
    meta: {
      title: '查询所有账号',
      icon: 'table'
    }
  }
  ]
},
{
  path: '/form/all/editAll',
  hidden: true,
  component: Layout,
  children: [{
    path: 'index/:id',
    name: 'editAll',
    component: () => import('@/views/form/all/editAll/index'),
    meta: {
      title: '编辑此账号',
      icon: 'form'
    }
  }]
},

{
  path: '/form/editattendance',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index/:code',
    name: 'editattendance',
    component: () => import('@/views/form/editattendance/index'),
    meta: {
      title: '修改考勤记录',
      icon: 'form'
    }
  }]
},

{
  path: '/form',
  component: Layout,
  hidden: true,
  children: [{
    path: 'index',
    name: 'Form',
    component: () => import('@/views/form/index'),
    meta: {
      title: 'Form',
      icon: 'form'
    }
  }]
},

{
  path: '/nested',
  component: Layout,
  hidden: true,
  redirect: '/nested/menu1',
  name: 'Nested',
  meta: {
    title: 'Nested',
    icon: 'nested'
  },
  children: [{
    path: 'menu1',
    component: () => import('@/views/nested/menu1/index'), // Parent router-view
    name: 'Menu1',
    meta: {
      title: 'Menu1'
    },
    children: [{
      path: 'menu1-1',
      component: () => import('@/views/nested/menu1/menu1-1'),
      name: 'Menu1-1',
      meta: {
        title: 'Menu1-1'
      }
    },
    {
      path: 'menu1-2',
      component: () => import('@/views/nested/menu1/menu1-2'),
      name: 'Menu1-2',
      meta: {
        title: 'Menu1-2'
      },
      children: [{
        path: 'menu1-2-1',
        component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
        name: 'Menu1-2-1',
        meta: {
          title: 'Menu1-2-1'
        }
      },
      {
        path: 'menu1-2-2',
        component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
        name: 'Menu1-2-2',
        meta: {
          title: 'Menu1-2-2'
        }
      }
      ]
    },
    {
      path: 'menu1-3',
      component: () => import('@/views/nested/menu1/menu1-3'),
      name: 'Menu1-3',
      meta: {
        title: 'Menu1-3'
      }
    }
    ]
  },
  {
    path: 'menu2',
    component: () => import('@/views/nested/menu2/index'),
    meta: {
      title: 'menu2'
    }
  }
  ]
},

{
  path: 'external-link',
  component: Layout,
  hidden: true,
  children: [{
    path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
    meta: {
      title: 'External Link',
      icon: 'link'
    }
  }]
},

// 404 page must be placed at the end !!!
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
